<?php
//
//	file: installer/inc_rank.php
//	begin: 08/05/2007
//	$Author: christopher $
//	$Revision: 29 $
//	$Date: 2008-07-19 15:59:35 +0000 (Sat, 19 Jul 2008) $
//	license: http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)

if ( !defined('IN_PHPBB') || !defined('IN_INSTALL') )
{
	die('Hack attempt !');
	exit;
}

class rank_install
{
	function rank_install()
	{
		global $config, $parms_def;

		// includes
		include($config->url('includes/aucp/class_rank'));
		lang_include('lang_CH_install_rank');

		// parms (not set is : type => TYPE_INT, default => 0)
		$parms_def += array(
			'rapv' => array('type' => TYPE_NO_HTML, 'default' => ''),
			'rand' => array('type' => TYPE_INT, 'default' => 0),
			'ramd' => array('type' => TYPE_INT, 'default' => 0),
		);

		return;
	}

	function start()
	{
		global $part_script, $page;

		// parms (not set is : type => TYPE_INT, default => 0)
		$part_script[] = sprintf($page->lang('RA_welcome_explain'), RANK_CURRENT_VERSION);

		return;
	}

	function prev_vers()
	{
		global $db, $page, $parms;

		// check
		$parms['rapv'] = false;

		// current line
		$parms['rapv'] = get_version('mod_aucp_rank');

		// title line  1.1.0
		$parms['rapv'] = ($parms['rapv'] === false) ? get_version('mod_custom_title') : $parms['rapv'];

		// title line 1.0.0
		$check = ($parms['rapv'] === false) ? get_version('custom_title_mode') : false;
		$parms['rapv'] = ($check) ? '1.0.0': $parms['rapv'];
		unset($check);

		if ($parms['rapv'])
		{
			$page->output(sprintf($page->lang('RA_previous_version'),$parms['rapv']));
		}

		return;
	}

	function db()
	{
		global $schemas, $parms;

		$parms['rand'] = $parms['ramd'] = false;

		// install schema
		switch ( $parms['rapv'] )
		{
			case '1.0.0':
			case '1.1.0':
				$schemas[] = 'rank_120';
				$parms['ramd'] = true;
			case '1.2.0':
				break;
			default:
				$schemas[] = 'rank_ch';
				$parms['rand'] = true;
				break;
		}
		return;
	}

	function migrate()
	{
		global $page, $db, $config, $parms;

		if (!$parms['ramd'])
		{
			return;
		}

		$config->set('aucp_rank_mode', $config->data['custom_title_mode'], true);
		$config->set('aucp_rank_days', $config->data['custom_title_days'], true);
		$config->set('aucp_rank_posts', $config->data['custom_title_posts'], true);
		$config->set('aucp_rank_html', 0, true);
		delete_version('custom_title_mode');
		delete_version('custom_title_days');
		delete_version('custom_title_posts');
		delete_version('mod_custom_title');

		$page->output('RA_migrate_succeed');

		return;
	}

	function init_data()
	{
		global $db, $page, $parms, $config;

		if ( !$parms['rand'] )
		{
			return;
		}

		$config->set('aucp_rank_mode', 0, true);
		$config->set('aucp_rank_days', 14, true);
		$config->set('aucp_rank_posts', 0, true);
		$config->set('aucp_rank_html', 0, true);

		return;
	}

	function patch()
	{
		global $config;

		if (!defined('RANK_CURRENT_VERSION'))
		{
			include($config->url('includes/aucp/class_rank'));
		}

		$config->set('mod_aucp_rank', RANK_CURRENT_VERSION, true);

		return;
	}

	function fin()
	{
		global $page, $parms;

		$page->output(empty($parms['rapv']) ? 'RA_install_done' : 'RA_install_upgraded');

		return;
	}
}

$parts[] = 'rank_install';

?>